package com.ai.controller.security;


import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.model.param.SysUserRoleRelationParam;
import com.ai.service.security.ISysUserRoleRelationService;
import com.ai.common.vaild.AddGroup;
import com.ai.common.vaild.UpdateGroup;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 用户角色关联关系表 前端控制器
 * </p>
 *
 * @author chen
 * @since 2023-04-04 19:46:07
 */
@RestController
@RequestMapping("/sys-user-role-relation")
public class SysUserRoleRelationController {


//    @ApiOperation("查看所有的用户及其关系")
//    @PostMapping("list")
//    public CommonResponse<String> page(@RequestBody @Validated({UpdateGroup.class}) SysUserRoleRelationParam  sysUserRoleRelationParam){
//
//        return sysUserRoleRelationService.updateRelation(sysUserRoleRelationParam);
//    }

    @Resource
    private ISysUserRoleRelationService sysUserRoleRelationService;
    @ApiOperation("新增用户角色关系表")
    @PostMapping("add")
    @EnterPathParamLog
    public CommonResponse<String> add(@RequestBody @Validated({AddGroup.class}) SysUserRoleRelationParam  sysUserRoleRelationParam){

        return sysUserRoleRelationService.add(sysUserRoleRelationParam);
    }
    @ApiOperation("删除用户角色关系")
    @PostMapping("delete")
    @EnterPathParamLog
    public CommonResponse<String> delete(@RequestBody Integer id){
        boolean b = sysUserRoleRelationService.removeById(id);
        if (b){
            return CommonResponse.ok("删除成功");
        }else {
            return CommonResponse.error("删除失败");
        }
    }


    @ApiOperation("更新用户角色关系表")
    @PostMapping("update")
    @EnterPathParamLog
    public CommonResponse<String> update(@RequestBody @Validated({UpdateGroup.class}) SysUserRoleRelationParam  sysUserRoleRelationParam){

        return sysUserRoleRelationService.updateRelation(sysUserRoleRelationParam);
    }



}

